package com.linux.huhx.utils;

import org.apache.commons.lang.ArrayUtils;

import java.util.Map;
import java.util.Set;

/**
 * Created by huhx on 2017-05-17.
 */
public class RegrexUtils {

    // 从map中替换模板，基础类
    public static String replaceFormMap(String string, Map<String, String> map) {
        Set<String> set = map.keySet();
        for (String str : set) {
            string = string.replace("${" + str + "}", map.get(str)); // 这里不能用replaceAll
        }
        return string;
    }

    // 从map中替换模板{name}
    public static String messageFormat(String string, String... replace) {
        if (ArrayUtils.isEmpty(replace)) {
            return string;
        }
        for (int i = 0; i < replace.length; i++) {
            string = string.replace("{" + i + "}", replace[i]);
        }
        return string;
    }
}
